package com.fs.activiti5.vo;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import lombok.AllArgsConstructor;
import lombok.Data;

import org.activiti.engine.IdentityService;
import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.runtime.ProcessInstance;

@Data
@AllArgsConstructor
public class HistoricProcessInstanceVo {
	 /** The process instance id (== as the id for the runtime {@link ProcessInstance process instance}). */
	  String id;
	  
	  /** The user provided unique reference to this process instance. */
	  String businessKey;

	  /** The process definition reference. */
	  String processDefinitionId;

	  /** The time the process was started. */
	  Date startTime;

	  /** The time the process was ended. */
	  Date endTime;
	  
	  /** The authenticated user that started this process instance. 
	   * @see IdentityService#setAuthenticatedUserId(String) */
	  String startUserId;
	  
	  /**
	   * The name for the process instance.
	   */
	  String name;

	public static List<HistoricProcessInstanceVo> list(List<HistoricProcessInstance> list) {
		List<HistoricProcessInstanceVo> result = new ArrayList<>();
		for(HistoricProcessInstance pin:list){
			System.out.println(pin);
			result.add(new HistoricProcessInstanceVo(pin.getId(),
					pin.getBusinessKey(),
					pin.getProcessDefinitionId(),
					pin.getStartTime(),
					pin.getEndTime(), 
					pin.getStartUserId(),
					pin.getName()));
		}
		return result;
	}
}
